<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>出险管理</title>
    <base href="${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/"/>
    <link rel="icon" href="/static/images/favicon.ico">
    <link rel="stylesheet" href="/static/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/layuimini.css" media="all">
    <link rel="stylesheet" href="/static/css/themes/default.css" media="all">
    <link rel="stylesheet" href="/static/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
</head>
<body class="layui-layout-body layuimini-all">
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>出险查询</legend>
            <div style="margin: 10px 10px 10px 10px;align-content: center">
                <form class="layui-form layui-form-pane" action="" style="align-content: center">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">查勘派工</label>
                            <div class="layui-input-inline" >
                                <select id="userName" name="userName" lay-verify="required"  lay-filter="business" class="select">
                                    <option value="" ></option>
                                </select>
                            </div>

                        </div>
                    </div>
                </form>
            </div>
        </fieldset>



        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">派工</a><%-- <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" id="shenhe" lay-event="shenhe"  disabled="">审核</a>--%>
        </script>

    </div>
</div>
<script src="/static/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="/static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    var userid ="";//表单对象值
    //var username="";
    layui.use(['form', 'table'], function () {
        var form = layui.form,
            table = layui.table


        form.on('select(business)',function(data){
            userid=data.value;
            //alert(JSON.stringify(data));
        });


        $.ajax({
            type:"POST",
            url: '/accident/selectName',
            dataType: "json",
            contentType: "application/json;charset=utf-8",
            success: function(data) {
                if (data!== null) {
                    $("#userName").empty();
                    $("#userName").append(new Option("请选择服务", "0"));
                    $.each(data.data, function(index, item) {
                        $('#userName').append(new Option(item.username,item.userid));
                        console.log(item);
                    });
                } else {
                    $("#userName").append(new Option("暂无数据", ""));
                }
                //重新渲染
                form.render("select");
            }
        });



        table.on('tool(currentTableFilter)', function (obj) {
            var accident=obj.data;
            var userId=userid;
            //var userName=username;
            //alert(JSON.stringify(userid));
            if (obj.event === 'edit') {
                $.ajax({
                    type:"POST",
                    url: '/warranty/insert?userId='+userId,
                    data: JSON.stringify(accident),
                    dataType: "json",
                    contentType: "application/json;charset=utf-8",
                    success: function(data) {
                        if(data.count==1){
                           layer.alert("请指定派工人员！");
                        }else if(data.count==0){
                            layer.alert("派工失败！");
                        }else if(data.count==2){
                            layer.alert("派工成功！");
                            obj.del();
                        }
                    }
                });

            }
            return false;
        });



       /* layui.$('#LAY-component-form-getval').on('click', function () {
            var data = form.val('example');
            alert(JSON.stringify(data));
        });*/


        table.render({
            elem: '#currentTableId',
            url: '/accident/select',
            //page: true, //开启分页
            //totalRow: true, //开启合计行
            height: 360,
            cols: [[
                {field: 'caseReportId', fixed: 'left', Width: 50, title: '报案编号', sort: true},
                {field: 'dangerTime', minWidth: 20, title: '出现时间'},
                {field: 'fullAddress', minWidth: 20, title: '出现地点', sort: true},
                {field: 'driverTel', minWidth: 20, title: '出现时间', sort: true},
                {field: 'jobState', minWidth: 20, title: '报案处理', sort: true},
                {title: '操作',  width: 165, align:'center',sort: true, fixed: 'right', toolbar: '#currentTableBar'}
            ]],
            //page: true,
            done: function (res, curr, count) {

                $(".layui-table-box").find("[data-field='id']").css("display", "none");


                $("[data-field='jobState']").children().each(function () {
                    if ($(this).text() == '1') {
                        $(this).text("待处理");
                        //$('#shenhe').button('disable');
                    } else if ($(this).text() == '2') {
                        $(this).text("接收");
                        //  $('#shenhe').button('enable');
                    } else if ($(this).text() == '3') {
                        $(this).text("暂存");
                        // $('#shenhe').button('disable');
                    } else if ($(this).text() == '4') {
                        $(this).text("已处理")
                        // $('#shenhe').button('di;sable');
                    } else if ($(this).text() == '5') {
                        $(this).text("退回");
                        //   $('#shenhe').button('disable');
                    }
                });
            }
        });
    });

</script>
</div>
</body>
</html>
